<?php
declare (strict_types = 1);

namespace app\middleware;

use think\facade\Log;

class SwLoginCheck
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $token = headerToken();
        if(!$token){
            echo json_encode(['code'=>401, 'msg'=>'请先登录']);exit;
        }
        $result = decode_token($token);
        if(!in_array(4,json_decode($result->role,true))){
            echo json_encode(['code'=>-1, 'msg'=>'你没有权限']);exit;
        }
        //todo 待开启绑定
//        checkBindPhone($token);
        return $next($request);
    }
}
